package cn.hjm.hrm.service.impl;

import cn.hjm.hrm.domain.Productstore;
import cn.hjm.hrm.dto.ProductDto;
import cn.hjm.hrm.mapper.ProductstoreMapper;
import cn.hjm.hrm.service.IProductstoreService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sharkbinbin
 * @since 2022-01-30
 */
@Service
public class ProductstoreServiceImpl extends ServiceImpl<ProductstoreMapper, Productstore> implements IProductstoreService {
    @Autowired
    private ProductstoreMapper productstoreMapper;
    @Override
    public Productstore getById(Long id) {
        return productstoreMapper.getById(id);
    }

    @Override
    @Transactional
    public void getNumber(ProductDto productDto) {
        //根据前段拿到当前数据的库存
        Productstore productstore = productstoreMapper.getById(productDto.getId());
        //原有库存
        Long number = productstore.getNumber();
        productstore.setNumber(number-productDto.getNumber());
        productstoreMapper.update(productstore, null);
    }
}
